package com.central.apps.handler.contract;

import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.common.exception.service.ServiceException;
import jodd.util.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class PanelistsHandler extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;

    @Override
    public void beforSave(String app, String objName, Map<String, Object> data, boolean isUpdate) throws Exception {

        if(!isUpdate){
            List<Map<String,Object>> list = handlerService.findBySql("select id from gq_panelists where name='"+ MapUtils.getString(data,"name") +"' and post='"+MapUtils.getString(data,"post")+"'" +
                    " and assistant ='"+MapUtils.getString(data,"assistant") +"' and workunit ='"+MapUtils.getString(data,"workunit") +"'");
            if(CollectionUtils.isNotEmpty(list)){
                throw new ServiceException("专家信息重复，请修改！");
            }
        }


    }
}
